# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_wx_basever=3.2

_realname=codeblocks-fortranproject
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
_basever=1.8
_revision=385
pkgver=${_basever}.r${_revision}
pkgrel=1
pkgdesc="FortranProject plugin for Code::Blocks IDE (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://www.codeblocks.org/'
msys2_repository_url="https://sourceforge.net/p/fortranproject/code/HEAD/tree/trunk/"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-codeblocks"
         "${MINGW_PACKAGE_PREFIX}-tinyxml"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw"
             "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-cb_headers"
             "zip"
             "subversion")
source=("fortranproject::svn+https://svn.code.sf.net/p/fortranproject/code/trunk#revision=$_revision"
        "001-fix-build-with-external-tinyxml.patch"
        "002-fix-install-destination.patch")
sha256sums=('SKIP'
            '5e5134dcaeded3d7370bbfdf952a74cc8d6224f5b5ad6ac5b29ead50b4d393a5'
            '7cb5176abb339f6f0f5ec9975ab3477c928df1bae102551dd65c0895bec5cffc')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd fortranproject

  apply_patch_with_msg \
    001-fix-build-with-external-tinyxml.patch \
    002-fix-install-destination.patch

  ./bootstrap
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CXXFLAGS+=" -Wno-ignored-attributes" \
  ../fortranproject/configure \
    --prefix="${MINGW_PREFIX}"

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  mv "${pkgdir}"${MINGW_PREFIX}/lib/codeblocks/bin/libFortranProject.dll \
    "${pkgdir}"${MINGW_PREFIX}/lib/codeblocks/plugins/
}
